package com.xyht.sca_s.student_manage_system.modules.rxRegistrationWelcome.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RequestPass;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationAdvance.entity.req.RxRegistrationAdvanceStudentInfoAddReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationWelcome.entity.req.*;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationWelcome.service.RxRegistrationWelcomeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.Future;

/**
 * <p>
 * 招生管理迎新管理 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-05-16
 */
@RestController
@RequestMapping("/rxRegistrationWelcome")
@SecretBody
public class RxRegistrationWelcomeController {


    @Resource
    private RxRegistrationWelcomeService rxRegistrationWelcomeService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    //分班
    @ApiOperation("分班前学生信息导出")
    @PostMapping("/groupClass/batch/export")
    public ResponseResult exportStuInfo(@RequestBody RxRegistrationAdvanceStudentInfoGroupClassExportReq exportReq,
                                        HttpServletResponse response) {
        ResponseResult responseResult;
        try {
            Future<ResponseResult> future = rxRegistrationWelcomeService.exportStuInfo(exportReq, response);
            while (true) {
                if (future.isDone()) {
                    break;
                }
            }
            responseResult = future.get();
        } catch (Exception e) {
            e.printStackTrace();
            responseResult = CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return responseResult;
    }

    @ApiOperation("批量导入分班信息")
    @PostMapping("/batch/add")
    public ResponseResult batchAddGroupClass(@RequestBody RxRegistrationAdvanceStudentInfoGroupClassBatchReq groupClassBatchReq, HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try{
            Future<ResponseResult> future = rxRegistrationWelcomeService.batchAddGroupClass(groupClassBatchReq,user_id);
            while (true){
                if (future.isDone()){
                    commonCodeEnum = future.get();
                    break;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    @ApiOperation("单个分班或者修改")
    @PostMapping("/groupClass")
    public ResponseResult groupClass(@RequestBody RxRegistrationAdvanceStudentInfoGroupClassReq groupClassReq) {
        return rxRegistrationWelcomeService.groupClass(groupClassReq);
    }

    @ApiOperation("查看分班列表")
    @GetMapping("/getGroupClassList")
    public ResponseResult getGroupClassList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "stuName", required = false) String stuName,
                                            @RequestParam(value = "planId") String planId,
                                            @RequestParam(value = "isGroupClass", required = false) Integer isGroupClass,
                                            @RequestParam(value = "middleSchoolId", required = false) String middleSchoolId,//初中毕业学校
                                            @RequestParam(value = "majorId", required = false) String majorId,//专业
                                            @RequestParam(value = "idCard", required = false) String idCard) {
        return rxRegistrationWelcomeService.getGroupClassList(pageSize, pageNum, stuName, isGroupClass, idCard,middleSchoolId,majorId,planId);
    }

    //获取第三阶段数据
    @ApiOperation("获取第三阶段数据")
    @GetMapping("/getWelcomeStuInfo")
    @RequestPass
    public ResponseResult getWelcomeStuInfo(@RequestParam(value = "idCard") String idCard) {
        return rxRegistrationWelcomeService.getWelcomeStuInfo(idCard);
    }

    @ApiOperation("支付")
    @PostMapping("/welComePayment")
    @RequestPass
    public ResponseResult welComePayment(@RequestBody RxRegistrationAdvanceStudentInfoAddReq addReq) {
        return rxRegistrationWelcomeService.welComePayment(addReq);
    }

    @ApiOperation("前两个阶段未添加学生信息时先添加基本信息再支付")
    @PostMapping("/addStuInfo")
    @RequestPass
    public ResponseResult addStuInfo(@RequestBody RxRegistrationAdvanceStudentInfoAddReq addReq) {
        return rxRegistrationWelcomeService.addStuInfo(addReq);
    }


}

